package com.woniu40.petai_manager.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;


import com.woniu40.petai_manager.entity.Permission;
import com.woniu40.petai_manager.mapper.PermissionMapper;
import com.woniu40.petai_manager.vo.PermissionVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Service
public class PermissionService {

    @Autowired
    PermissionMapper permissionMapper;

    public PageInfo<Permission> findAllPermission( Integer pageNum, Integer pageSize, String permissionName){
        PageHelper.startPage(pageNum,pageSize);
        List<Permission> permissions = permissionMapper.selectAll(permissionName);
        PageInfo<Permission> listPageInfo = new PageInfo<>(permissions);
        return listPageInfo;
    }


    public int addPermission(Permission permission){
        int insert = permissionMapper.insert(permission);
        return insert;
    }

    public int delete(Integer id){
        int i = permissionMapper.deleteByPrimaryKey(id);
        return i;
    }

    public int updateByPrimaryKey(Permission permission){
        int i = permissionMapper.updateByPrimaryKey(permission);
        return i;
    }

    public List<Permission> findParent(){
        List<Permission> permissions = permissionMapper.selectParent();
        return permissions;
    }
    public List<PermissionVo> findAllPermissionVo(){
        List<PermissionVo> allPermissionVo = permissionMapper.selectAllPermissionVo();
        return allPermissionVo;
    }



}
